/**
 * 通过调节电位器, 控制无源蜂鸣器的频率
 */

#define POT A0
#define BUZZER 2

int pot = 0;
int pwm = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(BUZZER, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  pot = analogRead(POT);
  pwm = map(pot, 0, 1023, 0, 255);
  Serial.println(pwm);
  // bi 一下
  for (int i=0;i<1000; i++){
    digitalWrite(BUZZER, HIGH);
    delayMicroseconds(pwm);
    digitalWrite(BUZZER, LOW);
    delayMicroseconds(pwm);
  }
  delay(1000);
}
